import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'dashboard' }
    }]
  },
  // 基础信息管理相关路由
  {
    path: '/information',
    component: Layout,
    redirect: '/information/warehouse',
    meta: { title: '基础信息管理', icon: 'el-icon-tickets' },
    children: [{
      path: 'warehouse',
      name: 'warehouse',
      component: () => import('@/views/warehouse/index'),
      meta: { title: '仓库管理' }
    },
    {
      path: 'warehouseDetails/:id',
      name: 'warehouseDetails',
      component: () => import('@/views/warehouseDetails/index'),
      hidden: true
      // meta: { title: '新建仓库' }
    },
    {
      path: 'area',
      name: 'area',
      component: () => import('@/views/area/index'),
      meta: { title: '库区管理' }
    },
    {
      path: 'location',
      name: 'location',
      component: () => import('@/views/location/index'),
      meta: { title: '库位管理' }
    },
    {
      path: 'view',
      name: 'view',
      component: () => import('@/views/view/index'),
      meta: { title: '库位视图' }
    },
    {
      path: 'product',
      name: 'product',
      component: () => import('@/views/product/index'),
      meta: { title: '货品管理' }
    },
    {
      path: 'type',
      name: 'type',
      component: () => import('@/views/type/index'),
      meta: { title: '货品类型管理' }
    }
    ]
  },
  // 商务管理相关路由
  {
    path: '/business',
    component: Layout,

    redirect: '/business/owner',
    meta: { title: '商务管理', icon: 'el-icon-tickets' },
    children: [{
      path: 'owner',
      name: 'owner',
      component: () => import('@/views/owner/index'),
      meta: { title: '货主管理' }
    },
    {
      path: 'carrier ',
      name: 'carrier',
      component: () => import('@/views/carrier/index'),
      meta: { title: '承运商管理' }
    }
    ]
  },
  // 库内管理相关路由
  {
    path: '/inWarehouse',
    component: Layout,

    redirect: '/inWarehouse/countSheet',
    meta: { title: '库内管理', icon: 'el-icon-tickets' },
    children: [{
      path: 'countSheet',
      name: 'countSheet',
      component: () => import('@/views/countSheet/index'),
      meta: { title: '盘点单' }
    },
    {
      path: 'countTask',
      name: 'countTask',
      component: () => import('@/views/countTask/index'),
      meta: { title: '盘点任务' }
    },
    {
      path: 'profitLoss',
      name: 'profitLoss',
      component: () => import('@/views/profitLoss/index'),
      meta: { title: '库存损益' }
    },
    {
      path: 'inventory',
      name: 'inventory',
      component: () => import('@/views/inventory/index'),
      meta: { title: '实时库存' }
    }
    ]
  },
  // 入库管理相关路由
  {
    path: '/entryWarehouse',
    component: Layout,

    redirect: '/entryWarehouse/entrySheet',
    meta: { title: '入库管理', icon: 'el-icon-tickets' },
    children: [{
      path: 'entrySheet',
      name: 'entrySheet',
      component: () => import('@/views/entrySheet/index'),
      meta: { title: '入库单' }
    },
    {
      path: 'receivingTask',
      name: 'receivingTask',
      component: () => import('@/views/receivingTask/index'),
      meta: { title: '收货任务' }
    },
    {
      path: 'launchTask',
      name: 'launchTask',
      component: () => import('@/views/launchTask/index'),
      meta: { title: '上架任务' }
    }
    ]
  },
  // 出库管理相关路由
  {
    path: '/exWarehouse',
    component: Layout,

    redirect: '/exWarehouse/exSheet',
    meta: { title: '出库管理', icon: 'el-icon-tickets' },
    children: [{
      path: 'exSheet',
      name: 'exSheet',
      component: () => import('@/views/exSheet/index'),
      meta: { title: '入库单' }
    },
    {
      path: 'pickingTask',
      name: 'pickingTask',
      component: () => import('@/views/pickingTask/index'),
      meta: { title: '拣货任务' }
    },
    {
      path: 'handoverTask',
      name: 'handoverTask',
      component: () => import('@/views/handoverTask/index'),
      meta: { title: '交接任务' }
    }
    ]
  },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
